﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace FXSStation.CustomControls.LineChart
{
    public class ChartStyle
    {
        private double _xmin = 0;
        private double _xmax = 1;
        private double _ymin = 0;
        private double _ymax = 1;
        private Canvas _chartCanvas;

        public ChartStyle(Canvas canvas)
        {
            this.ChartCanvas = canvas;
        }

        public Canvas ChartCanvas
        {
            get { return _chartCanvas; }
            set { _chartCanvas = value; }
        }
        public double Xmin
        {
            get { return _xmin; }
            set { _xmin = value; }
        }
        public double Xmax
        {
            get { return _xmax; }
            set { _xmax = value; }
        }
        public double Ymin
        {
            get { return _ymin; }
            set { _ymin = value; }
        }
        public double Ymax
        {
            get { return _ymax; }
            set { _ymax = value; }
        }


        public void ResizeCanvas(double width, double height)
        {
            ChartCanvas.Width = width;
            ChartCanvas.Height = height;
        }

        public Point NormalizePoint(Point pt)
        {
            if (ChartCanvas.Width == double.NaN)
                ChartCanvas.Width = 300;
            if (this.ChartCanvas.Height == double.NaN)
                ChartCanvas.Height = 300;

            Point result = new Point();
            result.X = (pt.X - Xmin) * ChartCanvas.Width / (Xmax - Xmin);

            result.Y = ChartCanvas.Height - (pt.Y - Ymin) * ChartCanvas.Height / (Ymax - Ymin);

            return result;
        }
    }
}
